import React from 'react'
import {Redirect} from "umi"
import {useAuth} from "../hooks"

type Props = {
    children:any
}

/**
 * 身份认证的组件
 * @param param0 
 * @returns 
 */
function auth(props: Props) {
    //告诉wrapper，结果就可以
    const isLogin = useAuth();
    // const isLogin = false
    // console.log(isLogin);
    
    if (isLogin) {
        //component对应组件
        return <div>{props.children}</div>;
    } else {
        return <Redirect to="/" />;
    }
}

export default auth